<?php
	require '../Class/autoload.php';
	date_default_timezone_set("Asia/Chongqing");



	//验证请求来路
	$uri = @$_SERVER["HTTP_REFERER"];
	if(!preg_match("/^https:\/\/servicewechat.com.*/",$uri)){
		exit('10001');	//请求来路非法
	}

	
	//解析数据库地址
	if(I('dbHost','p')){
		$db_host = IpDecrypt(I('dbHost','p'));
	}else{
		exit('10002');	//缺少库址
	}

	//拼接库名
	$cityCode = I('cityCode','p');
	if($cityCode){
		$db_name = 'shop_'.$cityCode;
	}else{
		exit('10003');	//缺少城市代码
	}


	//验证token
	$token = I('token','p');

	$a = substr($token, 0,1);
	$b = intval(substr($token,1,$a));	//基数
	$c = intval(substr($token,1+$a));	//倍数
	if($c/11/9/7/5/3 != $b){
		exit('10004');		//token验证失败
	}


	$type = I('type');

	switch($type){
		//获取商户列表
		case '_getStoreListAll':
			$markPath = './Mark/mark_getStoreListAll_'.$_POST['cityCode'];
			CheckMark($markPath);

			$tableShopStore = new TableShopStore();
			$res = $tableShopStore->_getStoreListAll($cityCode);
			echo json_encode($res);
		break;

		default:
			exit('default');
	}


//用于筛选并阻止小程序向后台同时过多的请求
function CheckMark($markPath){
	$mark = F($markPath);
	if($mark && $mark+15 > time()){
		exit;
	}
	@unlink($markPath);
	F($markPath,time());
}